home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Loadstar 14
/
014.d81
/
comal tutor #2
(
.txt
)
< prev
next >
Wrap
Commodore BASIC
|
2022-08-26
|
13KB
|
332 lines
1 goto 8
5 ifpeek(49152)<>120orpeek(51200)<>76orpeek(52016)<>32then7
6 ifpeek(52080)=173andpeek(52176)=169then8
7 load"routines",8,1
8 pokev+33,1:q$=chr$(34):vt$="":dimvt$(25)
9 fori=.to25:vt$(i)=left$(vt$,i+1):next:vt$=""
10 r=53265:c=128:v=53248:s=v+1024:li=52016:wi=51200:cl=51203:su=51206:sd=51209
12 pokes+23,.:pokes+4,128
15 gosub1000:print" [215]elcome to the second installment"
16 print"of [204]oadstar's [195][207][205][193][204][160]0.14 [212]utorial. [201]n
17 [153]"the first installment, you entered and
18 print"ran a short [195][207][205][193][204][160]program to convert
19 [153]"degrees ascarenheit into degrees lenelsius
20 print"without understanding how the program
21 [153]"worked. atnt the time, we were concen-
22 print"trating more on program entry.
23 [153]" (NULL)ow that we have the program in the
24 print"64's memory, let's see how it works.
25 s%[178][171]1:[141]1200
26 [153]" (NULL)e will assume that the computer is
27 print"just as we left it. [204][201][211][212][160]the program
28 [153]"to be sure it is still there:
30 gosub1160:gosub1300:x%=.:y%=16:a$="[204][201][211][212]":gosub1600
31 ifethena$=mid$(a$,e):e=.:gosub1605:goto31
32 x%=4:y%=16:gosub1500:ifk$<>chr$(13)then32
33 print:print"0010 [201][206][208][213][212] "q$"[196][197][199][210][197][197][211] [198]? "q$": [198][193][210][197][206][200][197][201][212]
34 [153]"0020 lenval(NULL)(NULL)right$(NULL)(NULL):=(ascatn(NULL)val(NULL)left$valright$(NULL)-32)*(5/9)
35 print"0030 [208][210][201][206][212] [198][193][210][197][206][200][197][201][212];"q$"[198] ="q$";[195][197][204][211][201][213][211];"q$"[195]"q$"
36 [141]1150:[153]"stop (NULL)ep, still there! mid$ust for prac-
37 print"tice, [210][213][206][160]the program and find out how
38 [153]"many degrees lenelsius -40 degrees "
39 [153]"ascarenheit converts into:
40 gosub1160:x%=.:y%=21:a$="[210][213][206]":gosub1600
41 ifethena$=mid$(a$,e):e=.:gosub1605:goto41
42 x%=3:y%=21:gosub1500:ifk$<>chr$(13)then42
43 print:print"[196][197][199][210][197][197][211] [198]? ";:
45 x%=11:y%=22:a$="-40":gosub1600
46 ifethena$=mid$(a$,e):e=.:gosub1605:goto46
47 x%=14:y%=22
48 gosub1500:ifk$<>chr$(13)then48
49 print:print"-40 [198] = -40 [195]":gosub1700
50 gosub1035:gosub1150:print"[144][146] [211]o -40 degrees is the 'meeting
51 [153]"place' for the two temperature scales!":[141]1205
55 [153]" (NULL)et's try one more. (NULL)ince 72 "
56 [153]"degrees ascarenheit is considered the "
57 [153]"most comfortable temperature for us
58 print"human beings, let's try to find the
59 [153]"lenelsius equivilant of 72 degrees asc:
60 gosub1160:gosub1300:x%=.:y%=24:a$="[210][213][206]":gosub1600
61 ifethena$=mid$(a$,e):e=.:gosub1605:goto61
62 x%=3:y%=24
63 gosub1500:ifk$<>chr$(13)then63
64 gosub1700:print"[196][197][199][210][197][197][211] [198]? ";
65 x%=11:y%=24:a$="72":gosub1600
66 ifethena$=mid$(a$,e):e=.:gosub1605:goto66
67 x%=13:y%=24
68 gosub1500:ifk$<>chr$(13)then244
69 gosub1700:print" 72 [198] = 22.2222222 [195]";:gosub1700:gosub1700:print"[145]"
70 gosub1035:gosub1150:print"[144][146] [211]o when it's around 22 [195]elsius"
71 print"outdoors, it's quite comfortable.
72 [153]" left$ow does this program work? right$n "
73 [153]"order to answer that, we must be able"
74 [153]"to see our program.
75 gosub1205
76 print" [201]n order to do [212][200][193][212], we must [204][201][211][212]
77 [153]"the program again. (peeket you'd (NULL)val(NULL)val(NULL)
78 print"have guessed!) [193]nyway, go ahead and
79 [153]"(NULL)right$(NULL)(NULL)closethe program again:
80 gosub1160:gosub1300:x%=.:y%=24:a$="[204][201][211][212]":gosub1600
81 ifethena$=mid$(a$,e):e=.:gosub1605:goto81
82 x%=4:y%=24:gosub1500:ifk$<>chr$(13)then82
83 gosub1700:print"0010 [201][206][208][213][212] "q$"[196][197][199][210][197][197][211] [198]? "q$": [198][193][210][197][206][200][197][201][212]";
84 gosub1700:print"0020 [195][197][204][211][201][213][211]:=([198][193][210][197][206][200][197][201][212]-32)*(5/9)";:gosub1700
85 print"0030 [208][210][201][206][212] [198][193][210][197][206][200][197][201][212];"q$"[198] ="q$";[195][197][204][211][201][213][211];"q$"[195]"q$;:gosub1700:gosub1700
86 gosub1035:gosub1150:print"[144] [212]he first line, line 10 (ignore the
87 [153]"leading zeroes for now), is an right$(NULL)(NULL)(NULL)(NULL)
88 print"statement. [193]n [201][206][208][213][212][160]statement's "
89 print"purpose is to [201][206][208][213][212] values into the "
90 print"program from the outside world, "
91 print"usually from the user via the":print"keyboard.":gosub1205
92 print"[201]t must [193][204][215][193][217][211] have a 'variable' that"
93 print"is simply a name given to the "
94 print"[201][206][208][213][212]ted data (in this case, the "
95 print"variable is named '[198][193][210][197][206][200][197][201][212]'). [193] "
96 print"variable name may consist of any "
97 print"number of letters or digits, so long"
98 print"as the first character is a letter.":print"[193]postrophes";
99 print" and left-arrow characters":print"are legal as well."
100 print"[212]he variable named in the [201][206][208][213][212]"
101 print"statement receives as its value the"
102 print"value 'keyed-in' by the user.":gosub1200
105 print" [212]his simply means that the [201][206][208][213][212]
106 [153]"statement displays the message between
107 print"the double-quote symbols, suspends the
108 [153]"execution of the program, and waits
109 print"for the user to type in something and
110 [153]"hit the (NULL)val(NULL)(NULL)(NULL)(NULL) key. right$f that something
111 print"is a legal number, the variable (in
112 [153]"this case, ascatn(NULL)val(NULL)left$valright$(NULL)) receives as its
113 print"value the number. [212]his means that,
114 [153]"from now on, whenever len(NULL)(NULL)atn(NULL)closeencounters
115 print"the word [198][193][210][197][206][200][197][201][212][160]within the program,
116 [153]"it will substitute the value typed in!":[141]1200
120 [153]" (NULL)he 'prompt string' is optional in
121 print"an [201][206][208][213][212][160]statement. [201]f no prompt is
122 [153]"specified, len(NULL)(NULL)atn(NULL)closedisplays a simple '?'
123 print"(question mark) to let the user know
124 [153]"that a response is requested from him.
125 print" [204]ine 20 (0020) is an example of an
126 [153]"'assignment' statement. atnn assignment
127 print"statement is used to assign a value to"
128 print"a variable. [193]n assignment statement"
129 print"gets its value for the variable from"
130 print"an expression." :gosub1200
131 :
132 :
133 print" [193]n 'expression' can be a [195][207][206][211][212][193][206][212],"
134 print"(such as 5 or 18.9), another variable,"
135 print"or a combination of constants and/or"
136 print"variables separated by [207][208][197][210][193][212][207][210][211]."
137 print"[207]perators represent mathematical"
139 print"operations such as '+' for addition,"
140 print"'-' for subtraction, '*' for"
141 print"multiplication, or '/' for division.)":gosub1200
145 print" [204]et's take a closer look at line
146 [153]"0020. 'lenval(NULL)(NULL)right$(NULL)(NULL)' is a variable, like
147 print"'[198][193][210][197][206][200][197][201][212]'. [201]t is the 'destination'
148 [153]"variable, the variable which will"
149 [153]"receive the value. (NULL)he two symbols"
150 [153]"after it (':=') form the 'assignment"
151 [153]"operator', which indeed is what tells"
152 [153]"us (and len(NULL)(NULL)atn(NULL)) that this is an"
153 [153]"assignment statement!
154 print" [212]he remainder of the line is the"
155 print"actual expression.":gosub1200
156 print" [212]he expression, in this case, is"
157 print"'([198][193][210][197][206][200][197][201][212]-32)*(5/9)'. [212]he parenthe-
158 [153]"ses are used to determine what to"
159 [153]"calculate first. right$n this case, '(5/9)'
160 print"is computed first, and the result of
161 [153]"'.555555556' is held in memory. (NULL)hen,
162 print"32 is subtracted